<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="signupForm" >
							<div class="form-group">
								<label class="col-sm-3 control-label">站点名：</label>
								<div class="col-sm-8">
									<input id="siteName" name="siteName" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">IP：</label>
								<div class="col-sm-8">
									<input id="ip" name="ip" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">域名：</label>
								<div class="col-sm-8">
									<input id="domainName" name="domainName"  class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">logo：</label>
								<div class="col-sm-8">
									<input id="logo" name="logo"  class="form-control"
										type="text"><button type="button" class="layui-btn" id="test1" onclick="sendFile()">
                            <i class="fa fa-cloud"></i>上传文件
                        </button>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">登陆背景：</label>
								<div class="col-sm-8">
									<input id="loginBg" name="loginBg" class="form-control" type="text">
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-3 control-label"></label>
								<div class="col-sm-8">
									<input id="备用文本框" name="备用文本框" class="form-control"
										type="hidden">
								</div>
							</div>

							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
									<button type="submit" class="btn btn-primary">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript" >
	$().ready(function() {
		validateRule();
	});

	$.validator.setDefaults({
		submitHandler : function() {
			save();
		}
	});
	function save() {
		$.ajax({
			cache : true,
			type : "POST",
			url : "/site/save",
			data : $('#signupForm').serialize(), // 你的formid
			async : false,
			error : function(request) {
				parent.layer.alert("网络超时");
			},
			success : function(data) {
				if (data.code == 0) {
					parent.layer.msg("操作成功");
					parent.reLoad();
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);

				} else {
					parent.layer.alert(data.msg)
				}

			}
		});

	}
	function validateRule() {
		var icon = "<i class='fa fa-times-circle'></i> ";
		$("#signupForm").validate({
			rules : {
				name : {
					required : true
				}
			},
			messages : {
				name : {
					required : icon + "请输入名字"
				}
			}
		})
	}
	
	//上传
	function sendFile(files, editor, $editable) {
	    var size = files[0].size;
	    if((size / 1024 / 1024) > 2) {
	        alert("图片大小不能超过2M...");
	        return false;
	    }
	    console.log("size="+size);
	    var formData = new FormData();
	    formData.append("file", files[0]);
	    $.ajax({
	        data : formData,
	        type : "POST",
	        url : "/common/sysFile/upload",    // 图片上传出来的url，返回的是图片上传后的路径，http格式
	        cache : false,
	        contentType : false,
	        processData : false,
	        dataType : "json",
	        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名
	            $('.summernote').summernote('insertImage',data.fileName);
	        },
	        error:function(){
	            alert("上传失败");
	        }
	    });
	}
	</script>
</body>
</html>
